package com.alibaba.cola.dto;

/**
 * Response to caller
 *
 * @author fulan.zjf 2017年10月21日 下午8:53:17
 */
public class Response extends DTO {

    /**
     * 系统异常
     */
    public static final Integer SYSTEM_ERROR = 500;
    /**
     * 正常请求返回code为0
     */
    public static final Integer OK = 0;


    private static final long serialVersionUID = 1165388793649327593L;

    private boolean success;

    private Integer code;

    private String message;

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    @Override
    public String toString() {
        return "Response [success=" + success + ", code=" + code + ", message=" + message + "]";
    }

    public static Response buildSuccess() {
        Response response = new Response();
        response.setSuccess(true);
        response.setCode(Response.OK);
        return response;
    }

    public static Response buildFailure(Integer code, String message) {
        Response response = new Response();
        response.setSuccess(false);
        response.setCode(code);
        response.setMessage(message);
        return response;
    }

}
